from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank
from typing import Optional
from module_admin.annotation.pydantic_annotation import as_query




class KeyModel(BaseModel):
    """
    UserKey表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='ID')
    user_id: Optional[int] = Field(default=None, description='用户ID')
    api_key: Optional[str] = Field(default=None, description='API-KEY')

    @NotBlank(field_name='api_key', message='API-KEY不能为空')
    def get_api_key(self):
        return self.api_key

    def validate_fields(self):
        self.get_api_key()




class KeyQueryModel(KeyModel):
    """
    UserKey不分页查询模型
    """
    pass


@as_query
class KeyPageQueryModel(KeyQueryModel):
    """
    UserKey分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteKeyModel(BaseModel):
    """
    删除UserKey模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    ids: str = Field(description='需要删除的ID')
